package com.nsn.vs.sdm.component.svn.command;

import java.io.File;

import java.text.DateFormat;
import java.util.Date;

import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.SVNInfo;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCClient;

import com.nsn.vs.sdm.component.svn.SvnClientManager;
import com.nsn.vs.sdm.util.string.UtilString;

/**
 * Used for executing fetch info operation.
 *
 * Available properties defined from info are:
 *  revisionProperty
 *  urlProperty
 *  repositoryRootUrlProperty 
 *  authorProperty 
 *  committedDateProperty 
 *  committedRevision
 *  
 * @author Jeccy.Zhao
 
 */
public class SvnCommandFetchInfo extends SvnCommand 
{
	
	/**
	 * The local path
	 */
	private String path;
	
	/**
	 * The sole constructor
	 * 
	 * @param manager
	 *          the svn client manager
	 * @param path
	 *          the local path
	 */
	public SvnCommandFetchInfo(SvnClientManager manager, String path) 
	{
		super(manager);
		
		this.path = UtilString.revertUnicodeChars(path);
	}
	
		
	/*
	 * (non-Javadoc)
	 * @see com.nsn.hzta.tcr.component.svn.Command#execute()
	 */
	@SuppressWarnings("unused")
	@Override
	public long execute () throws Exception 
	{
		File filePath = new File(this.path);
		
		DateFormat format = DateFormat.getInstance();
		
		// Get the WC Client
		SVNWCClient client = this.svnClient.getManager().getWCClient();
		
		// Execute svn info
		SVNInfo info = client.doInfo(filePath, SVNRevision.WORKING);
		
		// Get the interesting info data
		SVNRevision revision = info.getRevision();
		SVNRevision committedRevision = info.getCommittedRevision();
		SVNURL url = info.getURL();
		SVNURL repositoryRootUrl = info.getRepositoryRootURL();
		String author = info.getAuthor();
		Date committedDate = info.getCommittedDate();
		
		return -1L;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.nsn.hzta.tcr.component.svn.Command#validateAttributes()
	 */
	@Override
	protected void validateAttributes() throws Exception 
	{
	}
	
	public void setPath(String path) 
	{
		this.path = path;
	}
	
	public String getPath() 
	{
		return path;
	}

}
